package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo2 {
    public static void main(String[] args) {
        Collection<Integer> c = new ArrayList<>();
        c.add(6);
        c.add(66);
        c.add(666);
        c.add(6666);

        System.out.println("当前集合的个数:"+c.size());
        System.out.println("当前集合不是空集:"+c.isEmpty());

        int a = 66;
        boolean b = c.contains(a);
        System.out.println("集合中包含66:"+b);

        //c.clear();清空集合

        c.remove(a);
        System.out.println(c);

        Collection<Integer> c1 = new ArrayList<>();
        c1.add(7);
        c1.add(77);
        c1.add(777);

        c.addAll(c1);
        System.out.println(c);

        boolean d = c.containsAll(c1);
        System.out.println(d);

       // c.retainAll(c1);
        //System.out.println(c);取交集

        c.removeAll(c1);
        System.out.println(c);

        Iterator<Integer> it = c.iterator();
        while (it.hasNext()){
            Integer n = it.next();
            System.out.println(n);
        }

        for (Integer integer : c) {
            System.out.println(integer);
        }


    }
}
